﻿using MediatR;
using System.CJL.API.Application.Command.RawMaterialCommand;
using System.CJL.Infrstructre.Interface;

namespace System.CJL.API.Application.CommandHanlder.RawMaterialCommandHanler
{
    /// <summary>
    /// 原料添加
    /// </summary>
    public class RawMaterialAddCommandHandler : IRequestHandler<RawMaterialAddCommand, int>
    {
        IRawMaterialRepository _repository;
        /// <summary>
        /// 构造函数
        /// </summary>
        public RawMaterialAddCommandHandler(IRawMaterialRepository repository)
        {
            _repository = repository;
        }
        /// <summary>
        /// 原料添加方法
        /// </summary>
        public async Task<int> Handle(RawMaterialAddCommand request, CancellationToken cancellationToken)
        {
			DateTime localTime = DateTime.Now;
            var RawMaterialDate=request.RawMaterialDate.Value.ToUniversalTime();
			return await _repository.Addasync(new Domain.RawMaterial
            {
                RawMaterialNumbering = request.RawMaterialNumbering,
                RawMaterialName = request.RawMaterialName,
                RawMaterialClassify = request.RawMaterialClassify,
                RawMaterialSize = request.RawMaterialSize,
                RawMaterialSpecModel = request.RawMaterialSpecModel,
                RawMaterialAttribute = request.RawMaterialAttribute,
                RawMaterialUnit = request.RawMaterialUnit,
                RawMaterialinventory = request.RawMaterialinventory,
                RawMaterialType = request.RawMaterialType,
                RawMaterilStatus = request.RawMaterilStatus,
                RawMaterialNumber = request.RawMaterialNumber,
                RawMaterialDay = request.RawMaterialDay,
                InventoryMaximums = request.InventoryMaximums,
                InentoryLower = request.InentoryLower,
                RawMateriallocation = request.RawMateriallocation,
                RawMaterialDate =RawMaterialDate,
                RawMaterialReamrk = request.RawMaterialReamrk,
                RawMaterialImage = request.RawMaterialImage,
                IsDelete = false,
                AddTime = localTime.ToUniversalTime(),
                AddName = request.AddName,
            });
        }
    }
}
